package com.sun.web.service;

import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.sun.web.dao.UserDao;
import com.sun.web.domain.User;

@Service
public class UserService {
	
	@Autowired
	private UserDao userDao;
	
	public User getUserById(int userid){
		System.out.println("查询数据库 getUserById....");
		return userDao.getUserById(userid);
	}
	
	public User getUserByUsername(String username){
		System.out.println("查询数据库 getUserById....");
		return userDao.getUserByUsername(username);
	}
	
	public User getUserByToken(String token){
		return userDao.getUserByToken(token);
	}
	
	public int insertUser(User user){
		return userDao.insertUser(user);
	}
	
	public boolean checkUserExist(String username, String password){
		return userDao.checkUserExist(username, password);
	}
	
	public void updateUser(User user){
		userDao.updateUser(user);
	}
	
	@Cacheable(value="default", key="#root.methodName")
	public List<User> listUsers(){
		System.out.println("查询数据库");
		return userDao.listUsers();
	}
	
	@Cacheable(value="default", key="#root.methodName")
	public int getUserCount(){
		System.out.println("getUserCount 查询数据库");
		Integer count = userDao.getUserCount();
		return count;
	}
}
